/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.report.mapper.statistics;

import com.koron.report.bean.StatisticsBean;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface PerformMancePlanRateStatisticsMapper {

    /**
     * 统计计划定期检查总数，统计层级为员工
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @Select("<script>" +
            "SELECT  manager as code, COUNT(*) as value " +
            " FROM  check_record_produce " +
            " WHERE " +
            " (check_time BETWEEN  #{startTime} AND #{endTime})" +
            " GROUP BY manager" +
            "</script>")
    List<StatisticsBean> countPlanRegularCheckStatisticsByPerson(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /**
     * 统计实际定期检查总数，统计层级为员工
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @Select("<script>" +
            "SELECT  submit_code as code, count(*)  as value" +
            " FROM check_record " +
            " WHERE " +
            " ( check_time BETWEEN #{startTime} AND #{endTime}) " +
            " GROUP BY submit_code " +
            "</script>")
    List<StatisticsBean> countActualRegularCheckStatisticsByPerson(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /**
     * 统计实际临时检查总数，统计层级为员工
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @Select("<script>" +
            "SELECT  submit_code as code, count(*) as value " +
            " FROM check_record " +
            " WHERE " +
            "( check_time BETWEEN #{startTime} AND #{endTime})" +
            " AND plan_id IS  NULL " +
            " GROUP BY submit_code" +
            "</script>")
    List<StatisticsBean> countActualIRRegularCheckStatisticsByPerson(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /**
     *统计计划定期检查总数，统计层级为部门或集团
     * 区分方式，以是否传部门code集合区分，传，层级为部门。不传统计层级为集团
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param codeList 部门code集合
     * @return
     */
    @Select("<script>" +
            "SELECT  COUNT(*) as value " +
            " FROM  check_record_produce " +
            " WHERE " +
            " (check_time BETWEEN  #{startTime} AND #{endTime})" +
            "<if test='codeList!=null' >"+
            " and grid_code in"+
            "<foreach collection='codeList' item='code' open='(' close=')' separator=','>"+
            "   #{code}"+
            "</foreach>"+
            "</if>" +
            "</script>")
    Integer countPlanRegularCheckStatisticsByDeptOrGroup(@Param("startTime") Date startTime, @Param("endTime") Date endTime,@Param("codeList") List<String> codeList);

    /**
     * 统计实际定期检查总数，统计层级为部门或集团
     * 区分方式，以是否传部门code集合区分，传，层级为部门。不传统计层级为集团
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param codeList  部门code集合
     * @return
     */
    @Select("<script>" +
            "SELECT  count(*) as value " +
            " FROM check_record " +
            " WHERE " +
            "( check_time BETWEEN #{startTime} AND #{endTime})" +
            "<if test='codeList!=null' >"+
            " and grid_code in"+
            "<foreach collection='codeList' item='code' open='(' close=')' separator=','>"+
            "#{code}"+
            "</foreach>"+
            "</if>" +
            "</script>")
    Integer countActualRegularCheckStatisticsByDeptOrGroup(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
                                                                 @Param("codeList") List<String> codeList);

    /**
     * 统计实际临时检查总数，统计层级为部门或集团
     * 区分方式，以是否传部门code集合区分，传，层级为部门。不传统计层级为集团
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param codeList  部门code集合，
     * @return
     */
    @Select("<script>" +
            "SELECT count(*) as value " +
            " FROM check_record " +
            " WHERE " +
            "( check_time BETWEEN #{startTime} AND #{endTime})" +
            "<if test='codeList!=null' >"+
            " and grid_code in"+
            "<foreach collection='codeList' item='code' open='(' close=')' separator=','> #{code} </foreach>"+
            " AND plan_id IS  NULL" +
            "</if>"+
            "</script>")
    Integer countActualIRRegularCheckStatisticsByDeptOrGroup(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
                                                                   @Param("codeList") List<String> codeList);

    /**
     * 统计计划定期检查总数，统计层级为水司
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @Select("<script>" +
            "SELECT  corp_code as code, COUNT(*) as value " +
            " FROM  check_record_produce " +
            " WHERE " +
            " (check_time BETWEEN  #{startTime} AND #{endTime})" +
            " GROUP BY corp_code" +
            "</script>")
    List<StatisticsBean> countPlanRegularCheckStatisticsByCorp(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /**
     * 统计实际定期检查总数，统计层级为水司
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @Select("<script>" +
            "SELECT  corp_code as code, count(*) as value " +
            " FROM check_record " +
            " WHERE " +
            "( check_time BETWEEN #{startTime} AND #{endTime})" +
            " GROUP BY corp_code " +
            "</script>")
    List<StatisticsBean> countActualRegularCheckStatisticsByCorp(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /**
     * 统计实际临时检查总数，统计层级为水司
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @Select("<script>" +
            "SELECT  corp_code as code, count(*) " +
            " FROM check_record " +
            " WHERE " +
            "( check_time BETWEEN #{startTime} AND #{endTime})" +
            " AND plan_id IS  NULL " +
            " GROUP BY corp_code" +
            "</script>")
    List<StatisticsBean> countActualIRRegularCheckStatisticsByCorp(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /**
     *统计计划定期检查总数，统计层级为片区
     * 区分方式，以是否传部门code集合区分，传，层级为部门。不传统计层级为集团
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param codeList 部门code集合
     * @return
     */
    @Select("<script>" +
            "SELECT  COUNT(*) as value " +
            " FROM  check_record_produce " +
            " WHERE " +
            " (check_time BETWEEN  #{startTime} AND #{endTime})" +
            "<if test='codeList!=null' >"+
            " and corp_code in"+
            "<foreach collection='codeList' item='code' open='(' close=')' separator=','>"+
            "   #{code}"+
            "</foreach>"+
            "</if>" +
            "</script>")
    Integer countPlanRegularCheckStatisticsByDistrict(@Param("startTime") Date startTime, @Param("endTime") Date endTime,@Param("codeList") List<String> codeList);

    /**
     * 统计实际定期检查总数，统计层级为片区
     * 区分方式，以是否传部门code集合区分，传，层级为部门。不传统计层级为集团
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param codeList  部门code集合
     * @return
     */
    @Select("<script>" +
            "SELECT  count(*) as value " +
            " FROM check_record " +
            " WHERE " +
            "( check_time BETWEEN #{startTime} AND #{endTime}) " +
            "<if test='codeList!=null' >"+
            " and corp_code in"+
            "<foreach collection='codeList' item='code' open='(' close=')' separator=','>"+
            "   #{code}"+
            "</foreach>"+
            "</if>" +
            "</script>")
    Integer countActualRegularCheckStatisticsByDistrict(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
                                                           @Param("codeList") List<String> codeList);

    /**
     * 统计实际临时检查总数，统计层级为片区
     * 区分方式，以是否传部门code集合区分，传，层级为部门。不传统计层级为集团
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param codeList  部门code集合，
     * @return
     */
    @Select("<script>" +
            "SELECT count(*) as value " +
            " FROM check_record " +
            " WHERE " +
            "( check_time BETWEEN #{startTime} AND #{endTime})" +
            "<if test='codeList!=null '>"+
            " and corp_code in"+
            "<foreach collection='codeList' item='code' index='index' open='(' close=')' separator=','>"+
            "   #{code}"+
            "</foreach>"+
            " AND plan_id IS  NULL" +
            "</if>"+
            "</script>")
    Integer countActualIRRegularCheckStatisticsByDistrict(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
                                                             @Param("codeList") List<String> codeList);
}
